import {Component, OnInit} from '@angular/core';
import * as _ from 'lodash';
import {FetchService} from "../../../core/net/fetch.service";
import * as moment from "moment";
import {DispatchPlanService} from "../dispatch-plan.service";
import {UtilService} from "../../../core/util/util.service";
import { differenceInCalendarDays } from 'date-fns';
import { UniversalService } from '../../../core/util/universal.service';
import { ActivatedRoute, Router } from '@angular/router';

const reportTypeMap = {
    1: '未报送',
    2: '已报送'
};

const monthPlanTitleHash = {
    '4': '4月',
    '5': '5月',
    '6': '6月',
    '7': '7月',
    '8': '8月',
    '9': '9月',
    'd': '冬灌',
};

const glcMockData = [
    {name: '唐徕渠管理处', status: 1},
    {name: '西干渠管理处', status: 1},
    {name: '惠农渠管理处', status: 1},
    {name: '汉延渠管理处', status: 1},
    {name: '秦汉渠管理处', status: 2},
    {name: '唐徕渠管理处', status: 2},
    {name: '唐徕渠管理处', status: 2},
    {name: '唐徕渠管理处', status: 2},
    {name: '唐徕渠管理处', status: 2},
    {name: '唐徕渠管理处', status: 2},
    {name: '唐徕渠管理处', status: 2},
];

@Component({
    selector: 'app-slt-dispatch-plan',
    templateUrl: './slt-dispatch-plan.component.html',
    styleUrls: ['./slt-dispatch-plan.component.scss']
})
export class SltDispatchPlanComponent implements OnInit {
    selectedIndex = 0;  //  0-报送概览 1-年计划 2-月计划
    /******************* 报送概要 *********************/
    summaryType = 'year';   //  year-年概要 month-月旬概要

    glcFinishedNum = 0;
    glcUnfinishedNum = 0;
    glcPercentage: number | null = null;
    glcData = [];

    cityFinishedNum = 0;
    cityUnfinishedNum = 0;
    cityPercentage: number | null = null;
    cityVal = 0;
    cityTabs = [
        {
            name: '银川市',
            data: []
        },
        {
            name: '吴忠市',
            data: []
        },
        {
            name: '石嘴山市',
            data: []
        },
        {
            name: '中卫市',
            data: []
        },
        {
            name: '固原市',
            data: []
        }
    ];
    cityData = [];

    companyFinishedNum = 0;
    companyUnfinishedNum = 0;
    companyPercentage: number | null = null;
    companyData = [];

    glcMonthData = [];
    /**** 报送概要end ***/

    /*********************** 月旬计划 ********************/
    year = moment().valueOf();    // 默认今年
    manageId: string;
    monthSelection = '4';   //  4-9 d:冬灌
    monthPlanData = [];
    /************************ 月旬计划end ****/

    constructor(
        private fetchService: FetchService,
        private dispatchService: DispatchPlanService,
        private universalService: UniversalService,
        private router: Router,
        private util: UtilService,
        private routerInfo: ActivatedRoute,
    ) {
        this.selectedIndex = this.routerInfo.snapshot.queryParams['selectedIndex'] || 0;
    }

    ngOnInit() {
        const userInfo = this.universalService.getUserProfile() || {};
        this.manageId = userInfo["manageId"];
        this.getCurrentTabData();
    }

    formatPercentage = (percent: number) => `报送进度 ${percent}%`;

    getCurrentTabData(): void {
        switch (this.selectedIndex) {
            case 0:
                this.getSummaryData();
                break;
            case 1:
                break;
        }
    }

    getSummaryData(): void {
        this.glcData = glcMockData.map(item => {
            return _.assign(_.cloneDeep(item), {statusName: reportTypeMap[item.status]});
        });
    }

    getCityReportDetailData(): void {

    }

    onEdit(data, isEditable: boolean = false): void {
        this.router.navigate(['/dispatch-plan/slt-dispatch-detail'], { skipLocationChange: true, queryParams: {isEditable: isEditable, id: data.id}});

    }
    exportMonthFile(data): void {

    }

    sendToMng(data): void {

    }
}
